package ru.picman;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * Activity for the options-screen. Launched when "options" is selected from the main menu.
 * @author David
 *
 */
public class PicmanOptions
             extends Activity
{
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.picman_options);
		
		final TextView soundView1 = (TextView)findViewById(R.id.options_sound_text);
		final TextView soundView2 = (TextView)findViewById(R.id.options_sound_option);
		OnClickListener soundOCL = new OnClickListener() {
			public void onClick(View v) {
				soundView2.setText(soundView2.getText().equals("Off") ? "On" : "Off");
			}
		};
		soundView1.setOnClickListener(soundOCL);
		soundView2.setOnClickListener(soundOCL);
		soundView2.setText(sound);
		
		final TextView controlsView1 = (TextView)findViewById(R.id.options_controls_text);
		final TextView controlsView2 = (TextView)findViewById(R.id.options_controls_option);
		OnClickListener controlsOCL = new OnClickListener() {
			public void onClick(View v) {
				controlsView2.setText(controlsView2.getText().equals("Trackpad") ? "Touchscreen" : (controlsView2.getText().equals("Touchscreen") ? "Tilt" : "Trackpad"));
			}
		};
		controlsView1.setOnClickListener(controlsOCL);
		controlsView2.setOnClickListener(controlsOCL);
		controlsView2.setText(controls);
		
		final TextView difficultyView1 = (TextView)findViewById(R.id.options_difficulty_text);
		final TextView difficultyView2 = (TextView)findViewById(R.id.options_difficulty_option);
		OnClickListener difficultyOCL = new OnClickListener() {
			public void onClick(View v) {
				difficultyView2.setText(difficultyView2.getText().equals("Easy") ? "Medium" : (difficultyView2.getText().equals("Medium") ? "Hard" : "Easy"));
			}
		};
		difficultyView1.setOnClickListener(difficultyOCL);
		difficultyView2.setOnClickListener(difficultyOCL);
		difficultyView2.setText(difficulty);
		
		Button saveButton = (Button)findViewById(R.id.save_option);
		saveButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				sound = (String)soundView2.getText();
				controls = (String)controlsView2.getText();
				difficulty = (String)difficultyView2.getText();
				finish();
			}
		});
		Button discardButton = (Button)findViewById(R.id.discard_option);
		discardButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	//
	
	public static String sound = "Off";
	public static String controls = "Trackpad";
	public static String difficulty = "Medium";
}
